#pragma once

#include "BallType.h"

extern int g_iBallCount;

class CBallMesh
{
	private:
	enum {MESH_SIZE = 21};
	BallType::Type aeMesh[MESH_SIZE][MESH_SIZE];
	BallType::Type aeMeshSearchCopy[MESH_SIZE][MESH_SIZE];
	int aiColourMesh[MESH_SIZE][MESH_SIZE];
	float fBallSize;
	int iBallCount;
	float fNextBallTimer;
	float fNewBallTimer;
	sf::Vector2i i2NewBallIndices;
	BallType::Type eNewBall;
	bool bHamsterWin;
	bool bHamsterLose;
	int iColourCount;

	sf::Vector2i FindFirstFree(bool bWithoutNeighbours);
	void AddBall(sf::Vector2i i2Indices = sf::Vector2i(-1, -1), BallType::Type eType = BallType::Empty);
	std::vector<sf::Vector2i> GetSameColourNeighbourList(sf::Vector2i i2Point, BallType::Type eBallType);
	void ColourPoint(sf::Vector2i i2Point, int iColour);
	void ColourMesh(void);
	void LeaveBiggestGroup(void);

	public:
	CBallMesh(void);
	float Distance(sf::Vector2f f2Point1, sf::Vector2f f2Point2);
	sf::Vector2i GetMapPosition(sf::Vector2f f2Point);
	sf::Vector2f GetWorldPosition(sf::Vector2i i2Point);
	bool HasNeighbours(sf::Vector2i i2Pos);
	sf::Vector2i GetFirstNeighbour(sf::Vector2i i2Pos);
	void Load(int iInitialLength, int iLevel);
	void Update(float fDelta);
	void Display(void);
	bool HamsterWin(void);
	bool HamsterLose(void);
};
